package com.wwmz.spring.cloud.gateway.current;

import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * ip限流
 * created by wumz
 */
public class IPCurrent {

//    @Bean
//    public KeyResolver ipKeyResolver(){
//        //exchange.getRequest().getRemoteAddress().getHostName()
//        return exchange -> Mono.just(null);
//    }

    public static String getIpAddr(ServerHttpRequest request) {
        HttpHeaders headers = request.getHeaders();
        List<String> ips = headers.get("X-Forwarded-For");
        String ip = "192.168.1.1";
        if (ips != null && ips.size() > 0) {
            ip = ips.get(0);
        }
        return ip;
    }
}
